home *** CD-ROM | disk | FTP | other *** search
-
- package sub_arctic.lib;
-
- import sub_arctic.output.drawable;
- import sub_arctic.output.shadow_drawable;
-
- import java.awt.Dimension;
- import java.awt.Point;
-
- /**
- * This class provides a container that draws its child subtrees with a
- * shadow under them. This is done by drawing the children twice, once
- * with a shadow_drawable object (which turns all colors gray and offsets
- * the drawing slightly), then again on top normally. Shadow_graphics objects
- * have two drawing settings, expensive but accurate, and fast but inaccurate
- * (in particular drawing all images as filled rectangles). This setting can
- * also be made here and defaults to fast.
- *
- * @see sub_arctic.output.shadow_drawable
- * @author Scott Hudson
- */
- public class shadow_caster extends base_parent_interactor {
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Do we do expensive but realistic drawing of shadows for images, or do
- * we just do their bounding rectangle? Default is to be cheap about it.
- */
- protected boolean _expensive_draw = false;
-
- /**
- * Are currently doing expensive but realistic drawing shadows for images,
- * or do are we just drawing their bounding rectangle?
- * @return boolean true if we are doing expensive drawing.
- */
- public boolean expensive_draw() {return _expensive_draw;}
-
- /**
- * Set whether we draw image shadows realistically, but expensively (slow),
- * or just draw their bounding rectangles (fast).
- * @param boolean v the new setting (true for expensive).
- */
- public void set_expensive_draw(boolean v)
- {
- if (v != _expensive_draw)
- {
- _expensive_draw = v;
- damage_self();
- }
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Full constructor.
- * @param int xv the x position of the interactor.
- * @param int yv the y position of the interactor.
- * @param int wv the width of the interactor.
- * @param int hv the height of the interactor.
- * @param int shad_x the x offset of the shadow.
- * @param int shad_y the y offset of the shadow.
- */
- public shadow_caster(int xv, int yv, int wv, int hv, int shad_x, int shad_y)
- {
- super(xv,yv,wv,hv);
- _x_offset = shad_x;
- _y_offset = shad_y;
- _expensive_draw = false;
- }
-
- //had:
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Constructor with default shadow offsets.
- * @param int xv the x position of the interactor.
- * @param int yv the y position of the interactor.
- * @param int wv the width of the interactor.
- * @param int hv the height of the interactor.
- */
- public shadow_caster(int xv, int yv, int wv, int hv)
- {
- this(xv,yv,wv,hv,
- shadow_drawable.default_off_x,shadow_drawable.default_off_y);
- }
-
- //had:
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** X offset for shadow */
- protected int _x_offset;
-
- /**
- * X offset for shadow.
- * @return int the x offset of the shadow.
- */
- public int x_offset() {return _x_offset;}
-
- /**
- * Set x offset for shadow.
- * @param int xoff new x offset.
- */
- public void set_x_offset(int xoff)
- {
- /* need a redraw after this */
- damage_self();
-
- _x_offset = xoff;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Y offset for shadow */
- protected int _y_offset;
-
- /**
- * Y offset for shadow.
- * @return int the y offset of the shadow.
- */
- public int y_offset() {return _y_offset;}
-
- /**
- * Set y offset for shadow.
- * @param int yoff new y offset.
- */
- public void set_y_offset(int yoff)
- {
- /* need a redraw after this */
- damage_self();
-
- _y_offset = yoff;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Set offset for shadow.
- * @param int xoff new x offset.
- * @param int yoff new y offset.
- */
- public void set_offset(int xoff, int yoff)
- {
- /* need a redraw after this */
- damage_self();
-
- _x_offset = xoff;
- _y_offset = yoff;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Draw self. We draw our children twice, once in shadow offset by
- * a small translation, then again in normal colors.
- * @param drawable d the surface we draw on.
- */
- protected void draw_self_local(drawable d)
- {
- shadow_drawable shadow_d = new shadow_drawable(d,x_offset(),y_offset());
- shadow_d.set_expensive_draw(expensive_draw());
-
- draw_children(shadow_d);
- draw_children(d);
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Catch damage from our children and make it bigger to account for the
- * shadow.
- * @param Point top_left the top-left corner of the child damage (in our
- * coordinates).
- * @param Dimension sz the size of the damaged area.
- */
- public void damage_from_child(Point top_left, Dimension sz)
- {
- int px, py;
- Point new_pt;
- Dimension larger_sz;
-
- /* expand the size to include extra for the shadow */
- larger_sz = new Dimension(sz.width + Math.abs(_x_offset),
- sz.height+ Math.abs(_y_offset));
-
- /* if this was negative, move top & left edges */
- if (_x_offset < 0)
- px = top_left.x + _x_offset;
- else
- px = top_left.x;
- if (_y_offset < 0)
- py = top_left.y + _y_offset;
- else
- py = top_left.y;
- new_pt = new Point(px,py);
-
-
- /* let the superclass do the rest */
- super.damage_from_child(new_pt, larger_sz);
- }
-
- //had:
- //* @exception general PROPAGATED.
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
- }
-
-
- /*=========================== COPYRIGHT NOTICE ===========================
-
- This file is part of the subArctic user interface toolkit.
-
- Copyright (c) 1996 Scott Hudson and Ian Smith
- All rights reserved.
-
- The subArctic system is freely available for most uses under the terms
- and conditions described in
- http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html
- and appearing in full in the lib/interactor.java source file.
-
- The current release and additional information about this software can be
- found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
-
- ========================================================================*/
-